﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BuXiaChu.OrderDishes.BLL;
using BuXiaChu.OrderDishes.BLL.Constants;
using BuXiaChu.OrderDishes.Model;
using BuXiaChu.OrderDishes.BLL.CookieManager;

namespace BuXiaChu.OrderDishes.Web.CallCenter
{
    public partial class Notice : System.Web.UI.Page
    {
        protected int saveStatus = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                InitData();
            }
            else
            {
                Save();
            }
        }

        private void InitData()
        {
            List<ShareCodeModel> levelList = CodeDictionary.Instance.GetListByClassID(CodeDictionaryConstants.NoticeLevel);
            foreach (var item in levelList)
            {
                sel_Level.Items.Add(new ListItem(item.Name,item.CodeID.ToString()));
            }
        }

        private void Save()
        {
            if (string.IsNullOrEmpty(txt_Content.Value) == false)
            {
                NoticeBoardModel entity = new NoticeBoardModel();
                entity.Content = txt_Content.Value.Trim();
                entity.Level = int.Parse(sel_Level.Value);
                entity.Publisher = LoginSysUserInfo.Intance.RealName;
                entity.PublisherId = LoginSysUserInfo.Intance.EmploeeId;

                if (NoticeBoardManager.Save(entity))
                {
                    saveStatus = 1;
                }
                else
                {
                    saveStatus = 0;
                }
            }
        }
    }
}
